<?php
/**
 * File Name: SysConfigController.php
 *
 * Author: zl
 * Qq: 178417451
 * createTime 16/6/29 下午2:24
 */

namespace App\Http\Controllers\Admin;

use App\Models\SysConfig;
use Illuminate\Http\Request;

use App\Http\Requests;

class SysConfigController extends BaseController
{
    public function __construct(SysConfig $config)
    {
        parent::__construct();
        $this->model = $config;
    }

    public function getIndex()
    {
        $data = $this->model->getList();
        $uri = request()->all();
        return view('admin.sysconfig.index', compact('data', 'uri'));
    }

    public function postAdd()
    {
        $data = request()->except('_token');
        $res = $this->model->add($data);
        $status = 1;
        if(!$res)
        {
            $status = 0;
        }
        return $status;
    }

    public function postUpdate()
    {

        list($field, $id) = explode("-", request('datas'));
        $where['id'] = $id;
        $data[$field] = request('value');
        $res = $this->model->up($where, $data);
        $status = 1;
        if(!$res)
        {
            $status = 0;
        }
        return $status;
    }
}
